package com.zdp.security.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author ZhengDp
 * @Date 2023/7/21 21:23
 */
@Configuration
public class DemoWebSecurityConfig extends WebSecurityConfigurerAdapter {
    /*
    * 设置 用户和权限
    * */
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder())
                .withUser("zhengdp").password(new BCryptPasswordEncoder().encode("123456")).roles("admin")
                .and()
                .withUser("zz").password(new BCryptPasswordEncoder().encode("123456")).roles("user");
    }
}
